﻿function getParameterMap(form) {
    var p = document.forms[form].elements;
    var map = new Object();
    for(var x=0; x < p.length; x++) {
        var key = p[x].name;
        var val = p[x].value;

        //Check if this field name is unique.
        //If the field name is repeated more than once
        //add it to the current array.
        var curVal = map[key];
        if (curVal) { // more than one field so append value to array
        	curVal[curVal.length] = val;
        } else { // add field and value
        	map[key]= [val];
        }
    }
    return map;
}

function setFormAction(form, action, method) {
	if (action) {
		document.forms[form].setAttribute('action', action);
	}

	if (method) {
		document.forms[form].setAttribute('method', method);
	}

	document.forms[form].ec_eti.value='';
}

function setPresidentState(chkbx) {

	if (chkbx.checked) {

           var  chkbxNum= document.getElementsByName('primaryID');
           var chckHeader= true;
           for (var i=0; i< chkbxNum.length; i++){
              chckHeader= chckHeader && chkbxNum[i].checked;
           }
           if(chckHeader)
                document.getElementById('headerchk').checked = true;

	} else {

		 document.getElementById('headerchk').checked = false;
	}
}

function checkAll(obj){
    var chkbxs=document.getElementsByName('primaryID');
    for(var i = 0; i < chkbxs.length; i++){
        chkbxs[i].checked=obj.checked;
     	}
}


function trim(Str , Flag){
	Str	= ""+Str;
	if( Flag == "l" || Flag == "L" )/*trim left side only*/
	{
		RegularExp	= /^\s+/gi;
		return Str.replace( RegularExp,"" );
	}
	else if( Flag == "r" || Flag == "R" )/*trim right side only*/
	{
		RegularExp	= /\s+$/gi;
		return Str.replace( RegularExp,"" );
	}
	else/*defautly, trim both left and right side*/
	{
		RegularExp	= /^\s+|\s+$/gi;
		return Str.replace( RegularExp,"" );
	}
}

function checkpage(totalPages){

        var frm=document.getElementById('textNum').value;

        var action1=document.getElementById("ec").getAttribute("action");
       if( document.getElementById('ec_eti')!=null)
        document.getElementById('ec_eti').value="";

         var checknumber=/^[1-9][0-9]*$/;

        if( frm!=null && trim(frm)!=""){

              if(!checknumber.test(trim(frm))){
                  alert("请输入正确的页数！");
                  return;

              }else {

               var maxpage=eval(totalPages);
               var inputNum=eval(frm);

               if(inputNum>maxpage){
                 document.forms.ec.setAttribute('action',action1+"?method=list");
                 document.forms.ec.setAttribute('method','post');
                 document.forms.ec.ec_p.value=maxpage;
                 document.forms.ec.submit();
               }else{
               document.forms.ec.setAttribute('action',action1+"?method=list");
               document.forms.ec.setAttribute('method','post');
               document.forms.ec.ec_p.value=trim(frm);
               document.forms.ec.submit();
              }
              }
        }else{
            alert("页数为空，请输入正确的页数!");
            return;
        }
}
function setPageNumber(fromName,pageSize){
	document.forms[fromName].ec_p.value=pageSize;
}

function setFormAction(fromName,actionStr){
	document.forms[fromName].setAttribute("action",actionStr);
}
function formSubmit(fromName){
	document.forms[fromName].submit();
}


function getSelectIds(){
		var i;
		var selectedIds="";
		var trs=document.getElementById("ec_table").getElementsByTagName("tr");
		for(i=0;i<trs.length;i++){
			if(trs[i].className=='gridSelectOn'){
				if(selectedIds=="" && trs[i].id!="" && trs[i].id!="0"){
					selectedIds=trs[i].id;
				}else if(selectedIds!="" && trs[i].id!="" && trs[i].id!="0"){
					selectedIds=selectedIds+","+trs[i].id;
				}
			}
		}

		return selectedIds;

}